//-----------------------------------------------------------------------
// <copyright file="TerritoryService.cs" company="Pyramid Consulting">
//     Copyright (c) Pyramid Consulting. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------	

using System;
using System.Collections;
using MyFramework;
using MIMS.WRS.Entities;
using MIMS.WRS.Data;
    
namespace MIMS.WRS.Business
{   
	/// <summary>
	/// 
	/// </summary> 
    public class TerritoryService
    {

		public static TerritoryCollection GetTerritoriesByCountry(int countryId)
		{            
			try
			{
				TerritoryDAO territoryDAO = new TerritoryDAO();
				return territoryDAO.GetTerritoriesByCountry(countryId);
			}
			catch (BusinessException)
			{
				throw;
			}
			catch (Exception ex)
			{
				// log this exception
				Logger.Error(ex);
				// wrap it and rethrow
				throw new BusinessException(SR.BusinessGetTerritoriesException, ex);
			}
		}     

		public static TerritoryCollection GetTerritoriesForIDSByCountry(int countryId)
		{            
			try
			{
				TerritoryDAO territoryDAO = new TerritoryDAO();
				return territoryDAO.GetTerritoriesForIDSByCountry(countryId);
			}
			catch (BusinessException)
			{
				throw;
			}
			catch (Exception ex)
			{
				// log this exception
				Logger.Error(ex);
				// wrap it and rethrow
				throw new BusinessException(SR.BusinessGetTerritoriesException, ex);
			}
		}    

        #region Territory

        public static void CreateTerritory(Territory territory)
        {            
            try
            {
                TerritoryDAO territoryDAO = new TerritoryDAO();
                territoryDAO.CreateTerritory(territory);
            }
            catch (BusinessException)
            {
                throw;
            }
            catch (Exception ex)
            {
                // log this exception
                Logger.Error(ex);
                // wrap it and rethrow
                throw new BusinessException(SR.BusinessCreateTerritoryException, ex);
            }
        }        

        public static void UpdateTerritory(Territory territory)
        {            
            try
            {
                TerritoryDAO territoryDAO = new TerritoryDAO();
                territoryDAO.UpdateTerritory(territory);
            }
            catch (BusinessException)
            {
                throw;
            }
            catch (Exception ex)
            {
                // log this exception
                Logger.Error(ex);
                // wrap it and rethrow
                throw new BusinessException(SR.BusinessUpdateTerritoryException, ex);
            }
        }        

        public static void DeleteTerritory(int territoryID)
        {            
            try
            {
                TerritoryDAO territoryDAO = new TerritoryDAO();
                territoryDAO.DeleteTerritory(territoryID);
            }
            catch (BusinessException)
            {
                throw;
            }
            catch (Exception ex)
            {
                // log this exception
                Logger.Error(ex);
                // wrap it and rethrow
                throw new BusinessException(SR.BusinessDeleteTerritoryException, ex);
            }
        }
        
        public static Territory GetTerritory(int territoryID)
        {            
            try
            {
                TerritoryDAO territoryDAO = new TerritoryDAO();
                return territoryDAO.GetTerritory(territoryID);                
            }
            catch (BusinessException)
            {
                throw;
            }
            catch (Exception ex)
            {
                // log this exception
                Logger.Error(ex);
                // wrap it and rethrow
                throw new BusinessException(SR.BusinessGetTerritoryException, ex);
            }
        }                

        public static TerritoryCollection GetTerritories(TerritoryColumns orderBy, OrderDirection orderDirection)
        {            
            try
            {
                TerritoryDAO territoryDAO = new TerritoryDAO();
                return territoryDAO.GetTerritories(orderBy, orderDirection);
            }
            catch (BusinessException)
            {
                throw;
            }
            catch (Exception ex)
            {
                // log this exception
                Logger.Error(ex);
                // wrap it and rethrow
                throw new BusinessException(SR.BusinessGetTerritoriesException, ex);
            }
        }        

        public static TerritoryCollection GetTerritories(TerritoryColumns orderBy, OrderDirection orderDirection, int page, int pageSize, out int totalRecords)
        {            
            try
            {
                TerritoryDAO territoryDAO = new TerritoryDAO();
                return territoryDAO.GetTerritories(orderBy, orderDirection, page, pageSize, out totalRecords);
            }
            catch (BusinessException)
            {
                throw;
            }
            catch (Exception ex)
            {
                // log this exception
                Logger.Error(ex);
                // wrap it and rethrow
                throw new BusinessException(SR.BusinessGetTerritoriesException, ex);
            }
        }        

        #endregion
    }
}